package org.JWCB.common.core.domain.vo;


import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.JWCB.common.core.enums.ResultCode;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@ToString
public class TableDataInfo {
    /**
     * 数据数量
     */
    private Long total;


    /**
     * 列表数据
     */
    private List<?> rows;


    /**
     * 响应状态码
     */
    private int code;


    /**
     * 响应描述
     */
    private String msg;

    /**
     * @return 查询结果为空的表格数据
     */
    public static TableDataInfo empty() {
        TableDataInfo dataInfo = new TableDataInfo();
        dataInfo.setCode(ResultCode.SUCCESS.getCode());
        dataInfo.setMsg(ResultCode.SUCCESS.getMsg());
        dataInfo.setRows(new ArrayList<>());
        dataInfo.setTotal(0L);
        return dataInfo;
    }

    /**
     * @return 查询结果不为空的表格数据
     */
    public static TableDataInfo success(List<?> list,long total) {
        TableDataInfo dataInfo = new TableDataInfo();
        dataInfo.setCode(ResultCode.SUCCESS.getCode());
        dataInfo.setMsg(ResultCode.SUCCESS.getMsg());
        dataInfo.setRows(list);
        dataInfo.setTotal(total);
        return dataInfo;
    }
}
